package com.getpebble.android.common.core.async;

import android.os.AsyncTask;

public abstract class PblAsyncTask extends AsyncTask<Void, Void, Boolean> {
    public static final String TAG = PblAsyncTask.class.getSimpleName();

    public abstract boolean doInBackground();

    public abstract void onTaskFailed();

    public abstract void onTaskSuccess();

    public void submit() {
        executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[]{(Void) null});
    }

    public void cancel() {
        cancel(true);
    }

    protected Boolean doInBackground(Void[] params) {
        boolean success = doInBackground();
        if (success) {
            onTaskSuccess();
        } else {
            onTaskFailed();
        }
        return Boolean.valueOf(success);
    }

    protected void onPostExecute(Boolean success) {
    }
}
